<?php
namespace Home\Common\Behavior;
/**
 * 加载数据库中的配置
 */
class SetConfigBehavior {

    // 行为扩展的执行入口必须是run
    public function run(&$params){
        
        $this->setConfig();
    }   
    private function SetConfig() {
        $config =   S('DB_CONFIG_DATA');
        if(!$config){
            $config =   $this->get_config();
            S('DB_CONFIG_DATA',$config);
        }
        C($config);
    }

    private function get_config(){
        $group=array('Home','Common');
        $map=array(
            'module'    =>  array('IN',$group),
            'status'    =>  1
            );
        $config=array();
        $array=M('Config')->where($map)->field('key,value')->select();
        if(!empty($array)){
            foreach ($array as $key => $value) {
                $config[$value['key']]=$value['value'];
            }
        }
        return $config;
    }
}
